package cn.st4rlight.util.exception;

import cn.st4rlight.util.response.ResultCode;
import lombok.Getter;

/**
 * @author st4rlight <st4rlight@163.com>
 * Created on 2024-04-14
 */
@Getter
public class BizException extends RuntimeException {

    // 统一异常错误码
    private final ResultCode resultCode;


    public BizException(ResultCode resultCode, String message) {
        super(message);
        this.resultCode = resultCode;
    }

    public static BizException of(ResultCode resultCode) {
        return new BizException(resultCode, resultCode.getMsg());
    }

    public static BizException of(ResultCode resultCode, String errMsg) {
        return new BizException(resultCode, errMsg);
    }

    public static BizException paramInvalid(String errMsg) {
        return new BizException(ResultCode.PARAM_INVALID, errMsg);
    }

    public static BizException bizInvalid(String errMsg) {
        return new BizException(ResultCode.BIZ_CHECK_INVALID, errMsg);
    }
}
